package com.benshanyang.transformer;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yk.transformer.viewpager.AccordionTransformer;
import com.yk.transformer.viewpager.BackgroundToForegroundTransformer;
import com.yk.transformer.viewpager.CubeInTransformer;
import com.yk.transformer.viewpager.CubeOutTransformer;
import com.yk.transformer.viewpager.DefaultTransformer;
import com.yk.transformer.viewpager.DepthPageTransformer;
import com.yk.transformer.viewpager.FlipHorizontalTransformer;
import com.yk.transformer.viewpager.FlipVerticalTransformer;
import com.yk.transformer.viewpager.ForegroundToBackgroundTransformer;
import com.yk.transformer.viewpager.RotateDownTransformer;
import com.yk.transformer.viewpager.RotateUpTransformer;
import com.yk.transformer.viewpager.ScaleInOutTransformer;
import com.yk.transformer.viewpager.StackTransformer;
import com.yk.transformer.viewpager.TabletTransformer;
import com.yk.transformer.viewpager.ZoomInTransformer;
import com.yk.transformer.viewpager.ZoomOutSlideTransformer;
import com.yk.transformer.viewpager.ZoomOutTranformer;


public class ViewPagerFragment extends Fragment {

    private ViewPager viewPager;

    private int mParam1 = 0;
    private String animName = "";
    private static final String ARG_PARAM1 = "param1";

    public static ViewPagerFragment newInstance(int param1) {
        ViewPagerFragment fragment = new ViewPagerFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getInt(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_view_pager, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        viewPager = view.findViewById(R.id.view_pager);
        animName = "AccordionTransformer";
        switch (mParam1) {
            case 0:
                //AccordionTransformer
                animName = "AccordionTransformer";
                viewPager.setPageTransformer(true, new AccordionTransformer());
                break;
            case 1:
                //BackgroundToForegroundTransformer
                animName = "BackgroundToForegroundTransformer";
                viewPager.setPageTransformer(true, new BackgroundToForegroundTransformer());
                break;
            case 2:
                //CubeInTransformer
                animName = "CubeInTransformer";
                viewPager.setPageTransformer(true, new CubeInTransformer());
                break;
            case 3:
                //CubeOutTransformer
                animName = "CubeOutTransformer";
                viewPager.setPageTransformer(true, new CubeOutTransformer());
                break;
            case 4:
                //DefaultTransformer
                animName = "DefaultTransformer";
                viewPager.setPageTransformer(true, new DefaultTransformer());
                break;
            case 5:
                //DepthPageTransformer
                animName = "DepthPageTransformer";
                viewPager.setPageTransformer(true, new DepthPageTransformer());
                break;
            case 6:
                //FlipHorizontalTransformer
                animName = "FlipHorizontalTransformer";
                viewPager.setPageTransformer(true, new FlipHorizontalTransformer());
                break;
            case 7:
                //FlipVerticalTransformer
                animName = "FlipVerticalTransformer";
                viewPager.setPageTransformer(true, new FlipVerticalTransformer());
                break;
            case 8:
                //ForegroundToBackgroundTransformer
                animName = "ForegroundToBackgroundTransformer";
                viewPager.setPageTransformer(true, new ForegroundToBackgroundTransformer());
                break;
            case 9:
                //RotateDownTransformer
                animName = "RotateDownTransformer";
                viewPager.setPageTransformer(true, new RotateDownTransformer());
                break;
            case 10:
                //RotateUpTransformer
                animName = "RotateUpTransformer";
                viewPager.setPageTransformer(true, new RotateUpTransformer());
                break;
            case 11:
                //ScaleInOutTransformer
                animName = "ScaleInOutTransformer";
                viewPager.setPageTransformer(true, new ScaleInOutTransformer());
                break;
            case 12:
                //StackTransformer
                animName = "StackTransformer";
                viewPager.setPageTransformer(true, new StackTransformer());
                break;
            case 13:
                //TabletTransformer
                animName = "TabletTransformer";
                viewPager.setPageTransformer(true, new TabletTransformer());
                break;
            case 14:
                //ZoomInTransformer
                animName = "ZoomInTransformer";
                viewPager.setPageTransformer(true, new ZoomInTransformer());
                break;
            case 15:
                //ZoomOutSlideTransformer
                animName = "ZoomOutSlideTransformer";
                viewPager.setPageTransformer(true, new ZoomOutSlideTransformer());
                break;
            case 16:
                //ZoomOutTranformer
                animName = "ZoomOutTranformer";
                viewPager.setPageTransformer(true, new ZoomOutTranformer());
                break;
        }
        viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                Fragment fragment = TestFragment.newInstance(position, 0, animName);
                return fragment;
            }

            @Override
            public int getCount() {
                return 8;
            }
        });
    }

}